
import Vue from 'vue';
import Message from './elementui-message.js';

let util = {
  logout(){
    Vue.$cookies.remove('Authorization');
    localStorage.removeItem('Authorization');
    location.href = "#/";
  },
  isBlank(value){
    //undefined == null
    return value == null || value == '' || value == 'null';
  },
  goback(router){
    if(history.state){
      router.back(-1);
    }else{
      router.push('/');
    }
  },
  checkTextForbid(value){
    if(value.length > 512){
      Message('超出最大字符长度');
      return true;
    }
    if(value.length < 5){
      Message('最少5个字符');
      return true;
    }
    return false;
  },
  searchKeyExcute(store, input, route, router){
    store.commit('searchKeyExcute', input);
    if(route.path != '/index/allBook'){
      router.push('/index/allBook');
    }
  },
  getUserInfo(vm){
    vm.$http.postForm('/user/userInfo', null, res=>{
      vm.userInfo = res;
      vm.$cookies.set("nickname", res.nickName, 0);
    });
  }
}

export default util